<?php

namespace app\admin\controller;

/**
 * @title 用户登陆
 */
class Login extends Common
{

    /**
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function account()
    {
        if (input('username') && input('password')) {
            $userData = db('admin')->where(['username' => input('username'), "password" => md5(input('password'))])->find();
            $token = update_admin_token($userData['id']);
            if ($userData) {
                $data['userId'] = $userData['id'];
                $data['username'] = $userData['username'];
                $data['token'] = $token;
                $data['headUrl'] = 'https://testsyhbusiness-1253703708.cos.ap-guangzhou.myqcloud.com/icon/201808/08df2f0f-82bd-4592-80b2-07bbe26ca3b1.jpg';
                $this->rest($data);
            } else {
                $this->rest("登陆失败", 's004');
            }
        } else {
            $this->rest("用户名或密码不能为空", 's004');
        }

    }
}
